package com.fyyg.model;


import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.io.Serializable;

@Data
public class GenericResponse<T> implements Serializable {


    private String code;
    private String msg;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;

    public GenericResponse(){}
    public GenericResponse(String code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> GenericResponse<T> ok(){
        return new GenericResponse<T>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMsg(),null);
    }

    public static <T> GenericResponse<T> ok(T data){
        return new GenericResponse<T>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMsg(),data);
    }

    public static <T> GenericResponse<T> ok(String code,String msg,T data){
        return new GenericResponse<T>(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMsg(),data);
    }

    public static <T> GenericResponse<T> fail(T data){
        return new GenericResponse<T>(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getMsg(),data);
    }

    public static <T> GenericResponse<T> fail(String code,String msg,T data){
        return new GenericResponse<T>(code,msg,data);
    }

    public static <T> GenericResponse<T> fail(String code,String msg){
        return new GenericResponse<T>(code,msg,null);
    }
}
